package it.com.Test.a2_Serializable;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class TestOfThenAccept {

    static ExecutorService executor = Executors.newFixedThreadPool(3);

    /*
    accept 线程间传递结果，并返回最终结果
     */
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        System.out.println("main....start....");
        CompletableFuture<Void> completableFuture = CompletableFuture.supplyAsync(() -> {
            System.out.println("当前线程：" + Thread.currentThread().getId());
            int i = 10 / 2;
            System.out.println("运行结果：" + i);
            return i;
        }, executor).thenAccept((r) -> {
            System.out.println("二号获取一号任务的执行结果：" + r);
        });
        System.out.println("main....end....");

    }
}
